package qtgui

import (
    "log"
    "github.com/therecipe/qt/core"
    "github.com/therecipe/qt/gui"
    "github.com/therecipe/qt/widgets"

    "notabug.org/jazzyeagle/IDEa/lib"
)


type Editor struct {
    widgets.QTextEdit

    escapeMode  bool    `property:"escapeMode"`
}



//func (editor *Editor) init() {
//    editor.escapeMode = false
//    editor.SetFontFamily("Monospace")
//    editor.SetFontPointSize(14)
//}


func InitEditor(parent *widgets.QMainWindow) *Editor {
    var editor *Editor

    editor = NewEditor(parent)
    editor.escapeMode = false
    editor.SetFontFamily("Monospace")
    editor.SetFontPointSize(14)
    editor.ConnectKeyPressEvent(OnKeyPress)
    return editor
}


func OnKeyPress(e *gui.QKeyEvent) {
//func (editor *Editor) KeyPressEvent(e *gui.QKeyEvent) {
    var shortcut string

    if (e.Modifiers() != core.Qt__NoModifier) {
        shortcut = convertKeyPressEvent(e)
        lib.KeyPressed(shortcut)
    } else {
        e.Ignore()
    }
}


func convertKeyPressEvent(e *gui.QKeyEvent) string {
    var qks *gui.QKeySequence
    var shortcut string

    qks = gui.NewQKeySequence3(int(e.Modifiers())+e.Key(), 0, 0, 0)
    shortcut = qks.ToString(gui.QKeySequence__PortableText)
    log.Println("QKeySequence: ", shortcut)

    return shortcut
}
